<template>
  <basic-dialog
    width="60%"
    title="选择供应商"
    :visible="visible"
    :showFooter="false"
    :handleClose="handleCloseDialog"
  >
    <BasicForm
      :isScalingBtn="false"
      :hasQueryPermission="false"
      :formColumns="formItems"
      :dataSource="formData"
      :handleSearchForm="handleQueryForm"
      @getFormData="getFormData"
    />
    <SkusTable
      showActionCol
      showPagination
      :tableHeight="480"
      :dataSource="TableInfo.list"
      :columns="TableInfo.columns"
      :loading="TableInfo.loading"
      :pageSizes="pageSizes"
      :pagination="pagination"
      :total="total"
      :actionRender="renderTableBtnAction"
      @pageChange="handlePageChange"
      @pageSizeSelect="handlePageSizeChange"
    />
  </basic-dialog>
</template>
<script>
import BasicDialog from '@/components/BasicDialog';
import BasicForm from '@/components/BasicForm';
import SkusTable from '@/components/skusTable';
import skusPage from '@/mixins/commodity/skusPage';
import { getTableAction } from '@/utils/getBtnsRender';
import { getInitFormData, TableInfo } from '@/utils/getUtils';
import { FORM_ITEMS, TABLE_COLUMNS } from './constants';
import { getAllSupplierMainInfoService } from '@/api/commodity/temporaryPurchasingGoods/recordClueLatentSalePriceInfo';
export default {
  mixins: [skusPage],
  components: {
    BasicDialog,
    BasicForm,
    SkusTable
  },
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    validateSelect: {
      type: Function
    }
  },
  data () {
    return {
      formItems: FORM_ITEMS,
      formData: getInitFormData(FORM_ITEMS),
      TableInfo: new TableInfo({ columns: TABLE_COLUMNS }),
    }
  },
  methods: {
    // 渲染表格按钮
    renderTableBtnAction (h, { row }) {
      const actionList = [{
        label: '选择',
        method: this.handleSelect
      }]
      return getTableAction({ h, row, actionList })
    },
    // 获取表格数据
    async getTableData () {
      const data = {
        ...this.formData,
        ...this.paginationParams,
      }
      const res = await getAllSupplierMainInfoService(data, this.TableInfo.setLoading)
      this.TableInfo.setList(res?.retData?.results ?? [])
      this.setTotalNum(res?.retData?.totalNum ?? 0)
    },
    // 选择商品
    handleSelect (row) {
      this.$emit('getSupplierInfo', {
        ...row,
        supplierCode: row.supplierNo
      })
      this.handleCloseDialog()
    },
    // 关闭弹框
    handleCloseDialog () {
      this.$emit('update:visible', false)
    },
  }
}
</script>
<style lang="less" scoped>
/deep/ .el-dialog__header {
  border-bottom: 1px solid #e8eaec;
}
/* 分页样式 */
.pagination_wrap {
  display: flex;
  justify-content: center;
  margin-top: 20px;
}
</style>
